package com.xpalive.utils;

import com.xpalive.base.dto.result.RespResult;
import com.xpalive.exception.BizException;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletResponse;

public class XRespUtils {

    public static void resetResponse(HttpServletResponse response, RespResult<String> failure) {
        response.reset();
        response.setContentType("application/json");
        response.setCharacterEncoding("utf-8");
        try (PrintWriter writer = response.getWriter()) {
            writer.println(XJsonUtils.mapperIgnoreTimeFormatter.writeValueAsString(failure));
        } catch (IOException ex) {
            throw BizException.of(ex);
        }
    }
}
